﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FILSTARTUPS_CMS.Models;

namespace FILSTARTUPS_CMS.Helpers
{
    public class Authorization
    {
    }

    public class AdminAccessAttribute : AuthorizeAttribute
    {
        FilStartUpsEntities cms_dbconnect = new FilStartUpsEntities();

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null) throw new ArgumentNullException("httpContext");
            // Make sure the user is authenticated.
            if (httpContext.User.Identity.IsAuthenticated == false) return false;

            var user_role = cms_dbconnect.Users.Where(u => u.roleidFK.Equals(1) && u.Username.Equals(httpContext.User.Identity.Name)).SingleOrDefault();

            if (user_role != null)
            {
       
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}